cd "D:\uni\PIED3402"
ssc install estout
use 2017coop
set scheme s1mono
//data recoding//
rename faminc_new faminc
tab faminc
tab faminc, nol
drop if faminc == 97
drop if faminc == 98
tab race
tab race, nol
rename CC17_327 president
tab president
tab president, nol
recode president 9=. 8=. 5=. 4=. 3=2
label define president 1 "Trump" 2 "Other candidate"
label values president president
tab president, gen(president)
rename educ education
rename CC17_322a trumpapproval
recode trumpapproval 5=. 8=.
gen wwclass = 1 if faminc <=6 & race == 1
recode wwclass .=0
forvalues i = 1/6 {
	recode CC17_307_`i' (2=0) 
}
recode CC17_341A 8=. 2=0
recode CC17_341B 8=. 2=0
recode CC17_341C 8=. 2=0
recode CC17_341D 8=. 2=0
recode CC17_341E 8=. 2=0
recode CC17_341F 8=. 2=0
//0 is Oppose//
//Models and tables//
//Hypothesis 1//
logit president1 wwclass education gender
est store model3
esttab model3  using Table.rtf, ///
b(2) se(2)not pr2 obslast label title(Table 1. Logit model on voting for Trump) ///
nonumber mtitles("Voting for Trump")  gaps compress replace
margins, at (wwclass = (0 1))
marginsplot

//Hypothesis 2//
logit CC17_341A wwclass education gender
est store modela
margins, at (wwclass = (0 1))
marginsplot
logit CC17_341B wwclass education gender
est store modelb
margins, at (wwclass = (0 1))
marginsplot
logit CC17_341C wwclass education gender
est store modelc
margins, at (wwclass = (0 1))
marginsplot
logit CC17_341D wwclass education gender
est store modeld
margins, at (wwclass = (0 1))
marginsplot
logit CC17_341E wwclass education gender
est store modele
margins, at (wwclass = (0 1))
marginsplot

esttab modela modelb modelc modeld modele using Table3.rtf, ///
b(2) se(2)not pr2 obslast label title(Table 2 Logit models on support for Trumps’ executive actions) ///
nonumber mtitles("Travel ban" "Increase deportations" "Reduce regulations" "Leave Climate accord" "Buy American Hire American")  compress replace

//Hypothesis 3//
forvalues  i = 1/6 {
	quietly logit CC17_307_`i' wwclass education gender
	est store modelfp`i'
	margins, at (wwclass = (0 1))
}

esttab modelfp1 modelfp2 modelfp3 modelfp4 modelfp5 modelfp6 using Table4.rtf, ///
b(2) se(2)not pr2 obslast label title(Table 3. Logit models on foreign policy directed to North Korea) ///
nonumber mtitles("Don't get involved" "Negotiate to stop nukes" "Sanctions" "Sanctions NK trading partners" "Help South Korea" "Bomb")  compress replace


